package comp.style.state
{
	import comp.Interface.IDispose;
	import comp.UIComponent;

	/**
	 * 皮肤实现
	 */
	public class SkinState implements  IDispose
	{
		public function SkinState(ui:*)
		{
			_state=new Object();
			_ui=ui;
		}
		
		/**
		 * 状态改变
		 */
		public function changeState(stateName:String):void
		{
			var state:Istate=_state[stateName];
			var last:Istate=_state[_lastState];
			if(last)
				last.canelState(_ui);
			
			_lastState=stateName;
			
			if(state && state.state==0)
				state.create();
			
			if(state)
			{
				state.doState(_ui);
			}
		}
		
		public function doState(stateName:String):void
		{
			var state:Istate=_state[stateName];
			if(state)
				state.doState(_ui);
		}
		
		/**
		 * 注册状态
		 */
		public function registState(stateName:String,state:Istate):void
		{
			_state[stateName]=state;
		}

		public function get defaultSkin():Class
		{
			return _defaultSkin;
		}

		public function set defaultSkin(value:Class):void
		{
			_defaultSkin = value;
		}

		public function  dispose():void
		{
			_ui=null;
			_defaultSkin=null;
			_state=null;
			_lastState=null
		}
		
		
		private var _defaultSkin:Class;		
		private var _state:Object;//
		private var _ui:*;
		private var _lastState:String;//上个状态
	}
}